#include<iostream>
#include<string>
using namespace std;
bool check(string s){
    if(s.size()>16||s.size()<8){
        return false;
    }
        int a[4]={0},num=0;
        
    for(int i=0;i<s.size();i++){
        if('a'<=s[i]&&s[i]<='z'){
            a[0]=1;
        }else if('A'<=s[i]&&s[i]<='Z'){
            a[1]=1;
        }else if('0'<=s[i]&&s[i]<='9'){
            a[2]=1;
        }else if(s[i]=='@'||s[i]=='~'||s[i]=='!'||s[i]=='#'||s[i]=='$'||s[i]=='%'||s[i]=='^'){
            a[3]=1;
        }
    }
    for(int i=0;i<4;i++){
        if(a[i]==1){
            num++;
        }
    }
    if(num>=3){
        return true;
    }else return false;
}
int main(){
    int n;
    cin>>n;
    cin.ignore();
    for(int i=0;i<n;i++){
        string s;
        getline(cin,s);
        if(check(s)){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
}